package com.good.msgsys.dao;

import com.good.msgsys.entity.Award;
import com.good.msgsys.entity.response.AwardVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
 * @author junlong
 * @date 2021/1/7 17:37
 */
public interface AwardDao extends JpaRepository<Award, String>, JpaSpecificationExecutor<Award> {
    @Query(value = "SELECT new com.good.msgsys.entity.response.AwardVo(a.id, a.opusId, b.name, b.type, b.ids, b.state, b.publishTime) FROM Award a LEFT JOIN Opus b ON a.opusId = b.id",
        countQuery = "SELECT COUNT(id) FROM Award"
    )
    Page<AwardVo> findAllAward(Pageable pageable);
}
